package com.aaa.vip.controller;

import com.aaa.common.entity.UserAddress;
import com.aaa.common.util.BaseUtil;
import com.aaa.common.util.Result;
import com.aaa.common.vo.Page;
import com.aaa.vip.service.UserAddressService;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (UserAddress)表控制层
 *
 * @author makejava
 * @since 2025-09-20 09:27:30
 */
@RestController
@RequestMapping("userAddress")
@Log4j2
public class UserAddressController {
    /**
     * 服务对象
     */
    @Resource
    private UserAddressService userAddressService;
    /**
     *  根据token查询地址
     * @param
     * @return
     **/
    @GetMapping("queryDefaultAddress")
    public Result queryDefaultAddress() {
        return BaseUtil.success(this.userAddressService.queryDefaultAddress());
    }

    /**
     * 查询地址code
     * @return
     */
    @GetMapping("selectCode")
    public Result select(@RequestParam String country, @RequestParam String province) {
        return BaseUtil.success(this.userAddressService.selectCode(country, province));
    }
    /**
     * 查询所有地址根据userid
     * @return
     */
    @GetMapping("selectAllAddress")
    public Result selectAllAddress() {
        return BaseUtil.success(this.userAddressService.selectAllAddress());
    }

    /**
     * 分页查询
     *
     * @param page 分页对象
     * @return 查询结果
     */
    @PostMapping("queryByPage")
    public Result queryByPage(@RequestBody Page<UserAddress> page) {
        return BaseUtil.success(this.userAddressService.queryByPage(page));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("queryById")
    public Result queryById(Integer id) {
        return BaseUtil.success(this.userAddressService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param userAddress 实体
     * @return 新增结果
     */
    @PostMapping("add")
    public Result add(@RequestBody UserAddress userAddress) {
        return BaseUtil.success(this.userAddressService.insert(userAddress));
    }

    /**
     * 编辑数据
     *
     * @param userAddress 实体
     * @return 编辑结果
     */
    @PostMapping("edit")
    public Result edit(@RequestBody UserAddress userAddress) {
        return BaseUtil.success(this.userAddressService.update(userAddress));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("deleteById")
    public Result deleteById(Integer id) {
        return BaseUtil.success(this.userAddressService.deleteById(id));
    }

}

